'use strict';

const Controller = require('egg').Controller;

class DeleteaccountController extends Controller {
  async deleteAccount() {
    const { ctx } = this
    const { id } = ctx.params
    const { role } = await ctx.service.user.findById(id)
    if (role === 1) {
      ctx.body = {
        code: 1,
        msg: '不能删除超级管理员'
      }
      return
    }
    const result = await ctx.service.user.deleteUser(id)
    if (result.affectedRows === 1) {
      ctx.body = {
        code: 2,
        msg: '删除成功'
      }
    }
  }
}

module.exports = DeleteaccountController;
